<div class="sign-up">
	<div id="form-act-1">
		<em>Login:</em><input type="text" name="login" id="s-login"
			placeholder="Username or Email"> <em>Password:</em><input
			type="password" name="password" id="s-password"
			placeholder="Password" data-typetoggle='#show-password'> <input
			type="checkbox" id="show-password"><span
			id="show-password-span">Show password</span>
		<div id="sign-up" class="button"
			onclick="$('#form-act-1').hide();$('#form-act-2').show();">
			<span>Next</span>
		</div>
	</div>
	<div id="form-act-2" style="display: none">
		<em>Skills:</em><input type="text" name="skills" id="s-skills"
			placeholder="Your skills">
		<div id="sign-up-1" class="button prev"
			onclick="$('#form-act-1').show();$('#form-act-2').hide();">
			<span>Back</span>
		</div>
		<div id="sign-up-2" class="button finish" onclick="submitReg();">
			<span>Go!</span>
		</div>
	</div>
</div>
<script>
	!function() {
		$('#s-login').focus();
		$('.sign-up').draggable();
		$('input[name=login]').keyup(function(event) {
			if (event.keyCode == 13) {
				$('#s-password').focus();
			}
		});
		$('input[name=password]').keyup(function(event) {
			if (event.keyCode == 13) {
				$('#form-act-1').hide();
				$('#form-act-2').show();
				$('#s-skills').focus();
			}
		});
		$('input[name=skills]').keyup(function(event) {
			if (event.keyCode == 13) {
				submitReg();
			}
		});
		$('#s-password').showPassword();
	}()
	function submitReg() {
		if ($('#s-login').val() == '' || $('#s-password').val() == '') {
			$('#form-act-1').show();
			$('#form-act-2').hide();
			$('#s-login').attr('required', 'required');
			$('#s-password').attr('required', 'required');
			return;
		}
		$.cookie('uid', $('#s-login').val());
		$.ajax({
			url : '/s/?action=register',
			data : 'login=' + $('#s-login').val() + '&password=' + $('#s-password').val() + '&skills='
					+ $('#s-skills').val(),
			success : function(resp) {
				if (resp.success === true) {
					console.log('Registration successfull');
					$.cookie('uid', $('#s-login').val(), {
						expires : 365,
						path : '/'
					});
					window.location.reload();
				} else {
					$('#form-act-1').prepend('<em style=\'color:red;\'>' + resp.err + '</em>');
					$('#form-act-1').show();
					$('#form-act-2').hide();
					$('#s-login').attr('required', 'required');
					return;
				}
			}
		});
	}
</script>